package com.bawei.attendance.view

import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.attendance.R
import com.bawei.attendance.databinding.ActivityAttendanceBinding
import com.bawei.base.RoutePath
import com.bawei.common.base.BaseActivity

@Route(path = RoutePath.PATH_ATTENDANCE_PAGE)
class AttendanceActivity : BaseActivity<ActivityAttendanceBinding>() {

    @Autowired
    @JvmField
    var moduleType: String = "11"

    override fun getLayoutId(): Int = R.layout.activity_attendance

    override fun initView() {
        ARouter.getInstance().inject(this)

        initModuleFragment()
        //返回点击事件
        mDataBinding.includePageTitle.ivBack.setOnClickListener {
            this@AttendanceActivity.finish()
        }

    }

    private fun initModuleFragment(){
        when(moduleType){
            "11" -> {
                mDataBinding.includePageTitle.tvTitle.text = "签到"
                commitFragment(SignFragment.newInstance(), moduleType)
            }
            "12" -> {
                mDataBinding.includePageTitle.tvTitle.text = "考勤管理"
                commitFragment(AttendanceManagerFragment.newInstance(), moduleType)
            }
        }
    }

    /**
     * 提交Fragment到当前Activity
     */
    private fun commitFragment(moduleFragment: Fragment, fragmentTag: String){
        //1.获取FragmentManager对象
        var fm = supportFragmentManager
        //2.开启事务
        var fragmentTransaction = fm.beginTransaction()
        //3.提交事务
        fragmentTransaction.replace(R.id.fragment_container, moduleFragment, fragmentTag)
        fragmentTransaction.commit()
    }

}